<html>
    <?php
    session_start();
    include "jquery.php"
    //the javescript function that displays the calendar
    ?>
    <script type="text/javascript" src="calendar.js"></script>
    <script type="text/javascript">
        function init(id) {
            calendar.set(id);
        }
    </script>

    <head>
        <link rel="stylesheet" type="text/css" href="style3.css"/>

    </head>
    <body>
        <form name= "form" action = "" value = "Submit" method = "Post">

            <?php
            //Author:Mohamed Tarek


            $member_id = $_SESSION['member_id'];
            $conference_id = intval($_GET['conference_id']);
            /*
             * function EditInfo takes conference id and returns table with all  
             * info about the conference in textboxes to be edited
             */

//connect to the database
            $conn = @mysql_connect("localhost", "root", "") or die(mysql_error());
            mysql_select_db("mydb") or die(mysql_error());

            mysql_select_db("mydb", $conn);



            echo "<h1>Edit Conference Information</h1>";
            /*
             * query that populates all the info of the conference from the db
             */

            $get_conf_info = mysql_query("SELECT * 
                                    FROM conference 
                                    WHERE conference_id = '$conference_id'") or die(mysql_error());
            while ($row = mysql_fetch_assoc($get_conf_info)) {
//open table
                echo "<table>";
                /*
                 * print Long Name in a row 
                 * and in the column next to it print long_name from db inside the textbox 
                 * and setting its size . 
                 */
                echo "<tr>
         <td><b>Long name:</b></td>
         <td><input type =\"text\" size=\"50\" name =\"long\" value=\"$row[long_name]\"/></td>
         </tr>";
                /*
                 * print Short Name in a row 
                 * and in the column next to it print short_name from db inside the textbox  
                 * and setting its size .
                 */
                echo "<tr>
        <td><b>Short name:</b></td>
        <td><input type =\"text\" size=\"50\" name =\"short\" value=\"$row[short_name]\"/></td>
        </tr></table>";
                /*
                 * print Description in a row 
                 * and in the column next to it print fescription from db inside the textarea
                 * and setting its size . 
                 *  
                 */
                echo "<table><tr>
        <td><b>Description:</b><br>
                    <textarea rows=\"6\" cols=\"70\" name =\"desc\">$row[description]</textarea>
        
        </tr></table>";
                /*
                 * print Place in a row 
                 * and in the column next to it print place from db inside the textbox 
                 * and setting its size . 
                 */
                echo "<table><tr>
        <td><b>Place:</b></td>
        <td><input type =\"text\" size=\"50\" name =\"place\" value=\"$row[place]\"/></td>
        </tr>";
                /*
                 * print Conference Date in a row 
                 * and in the column next to it print conferenced_date from db inside the textbox 
                 * and setting its size.
                 * and the java script function which creates the calender 
                 */

                echo "<tr>
        <td><b>Conference Date</b></td>
        <td><input type =\"text\" size=\"50\" id=\"confdate\" onfocus=\"javascript: init('confdate')\" name =\"confdate\" value=\"$row[conference_date]\"/></td>
        </tr></table><br>";

                echo '<p><b>Submission Dates:</b></p><table>';
                //this query that select the deadline of the date and the name of the category. 
                $get_conf_rev = mysql_query("SELECT c.category_id, c.category, cc.submission_date
                          FROM conference_category cc INNER JOIN category c
                          ON c.category_id = cc.category_id
                          WHERE cc.conference_id = '$conference_id'") or die(mysql_error());
                //while loop inorder to print in order from the array.
                $j = 1;
                while ($row = mysql_fetch_assoc($get_conf_rev)) {
                    //prints the category
                    //create textbox and store in it the submission date from before and update in it.
                    echo "<tr>
                            <td><b>" . $row['category'] . "</b></td>
                                <td> <input type=\"textbox\" id=\"date{$j}\" onfocus=\"javascript: init('date{$j}')\" name=\"date{$j}\" value=\"{$row['submission_date']}\"/>
                                </td>
                                <td><input type=\"hidden\" name=\"categoryid{$j}\" value=\"{$row['category_id']}\"/>
                                </td>
                                </tr>";
                                $j++;
                }
                //Creating checkbox with name delete2 with name Insert2
                //echo
            }
            echo "</table>";
            echo "<br>";
            echo "<input type =\"submit\" name = \"submitButton\" value = \"Save\" />";
            //if submit button was  clicked
            if (isset($_POST['submitButton'])) {
 
                $long = $_POST['long'];
                $short = $_POST['short'];
                $desc = $_POST['desc'];
                $place = $_POST['place'];
                $confdate = $_POST['confdate'];
               
                //query that updates table conference with new info from textboxes

                mysql_query("UPDATE conference
                            SET  long_name  = '$long',
                            short_name = '$short',
                            description = '$desc',
                            place = '$place',
                            conference_date = '$confdate'
                            WHERE conference_id = '$conference_id'") or die(mysql_error());
                // this query used to get category id, category and submission date.
                $q = mysql_query("SELECT c.category_id, c.category, cc.submission_date
                          FROM conference_category cc INNER JOIN category c
                          ON c.category_id = cc.category_id
                          WHERE cc.conference_id = '$conference_id'") or die(mysql_error());
                $x = mysql_num_rows($q);
                
                // this for loop is looping on x inorder to get the data in the text fields and update it in the database.
                for ($i = 1; $i <= $x; $i++){
                    //set the information in $date.$i to subm.
                    $subm = $_POST['date'.$i];
                    //set the information in $categoryid.$i to $catIDs.
                    $catIDs = $_POST['categoryid'.$i];
                 // query is updating the submission date in confereance_category table. 
                    mysql_query("UPDATE conference_category
                            SET submission_date = '$subm'
                            WHERE conference_id = '$conference_id' AND category_id='$catIDs' ") or die(mysql_error());
                }

            }


            //End of Documntation
            ?>
        </form>
    </body>
</html>
